
//初始化数据
const app = getApp()

function tabbarinit() {
  return [
    {
      "current": 0,
      "pagePath": "/pages/index/index",
      "iconPath": 'http://img.hmeshop.cn/hmeshop_jxy/images/yyticon_1.png',
      "selectedIconPath": "http://img.hmeshop.cn/hmeshop_jxy/images/yyticon_2.png",
      "text": "首页",
      "width": 47
    },
    {
      "current": 0,
      "pagePath": "/pages/integralShop/integralShop",
      "iconPath": "http://img.hmeshop.cn/hmeshop_jxy/images/icon_zhuanqian.png",
      "selectedIconPath": "http://img.hmeshop.cn/hmeshop_jxy/images/icon_zhuanqian_seleted.png",
      "text": "积分商城",
      "width": 43
    },
    {
      "current": 0,
      "pagePath": "/pages/cart/cart",
      "iconPath": "http://img.hmeshop.cn/hmeshop_jxy/images/icon_gouwuche@2x.png",
      "selectedIconPath": "http://img.hmeshop.cn/hmeshop_jxy/images/icon_gouwuche@2x (1).png",
      "text": "购物车",
      "width": 59
    },
    {
      "current": 0,
      "pagePath": "/pages/member/member",
      "iconPath": "http://img.hmeshop.cn/hmeshop_jxy/images/icon_wode@2x (1).png",
      "selectedIconPath": "http://img.hmeshop.cn/hmeshop_jxy/images/icon_wode@2x.png",
      "text": "我的",
      "width": 42
    }
  ]

}

/**
 * tabbar主入口
 * @param  {String} bindName 
 * @param  {[type]} id       [表示第几个tabbar，以0开始]
 * @param  {[type]} target   [当前对象],
 * cartnumber 购物车数量
 */
function tabbarmain(bindName = "tabdata", id, target,cartNumber) {
  var that = target;
  var bindData = {cartNumber:cartNumber};
  var otabbar = tabbarinit();
  if (id == -1){
    id = 0
    otabbar[id]['current'] = 0;
    otabbar[id]['iconPath'] = otabbar[id]['iconPath']//换当前的icon
  }
  else {
    otabbar[id]['iconPath'] = otabbar[id]['selectedIconPath']//换当前的icon
    otabbar[id]['current'] = 1;
  }
  bindData[bindName] = otabbar
  that.setData({ bindData });
}


module.exports = {
  tabbar: tabbarmain
}